using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class RadiologyController : Controller
    {
		private readonly IRadiologyGroupRepository radiologygroupRepository;
		private readonly IRadiologyAttachmentRepository radiologyattachmentRepository;
		private readonly IRadiologyRepository radiologyRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public RadiologyController() //: this(new RadiologyGroupRepository(), new RadiologyAttachmentRepository(), new RadiologyRepository())
        {
            this.radiologyattachmentRepository=Registry.RepositoryFactory.GetRadiologyAttachmentRepository();
                this.radiologygroupRepository=Registry.RepositoryFactory.GetRadiologyGroupRepository();
                this.radiologyRepository = Registry.RepositoryFactory.GetRadiologyRepository();
        }

        public RadiologyController(IRadiologyGroupRepository radiologygroupRepository, IRadiologyAttachmentRepository radiologyattachmentRepository, IRadiologyRepository radiologyRepository)
        {
			this.radiologygroupRepository = radiologygroupRepository;
			this.radiologyattachmentRepository = radiologyattachmentRepository;
			this.radiologyRepository = radiologyRepository;
        }

        //
        // GET: /Radiology/

        public ViewResult Index()
        {
            return View(radiologyRepository.All);//Including(radiology => radiology.Group, radiology => radiology.Attachment, radiology => radiology.Items, radiology => radiology.Attachments));
        }

        //
        // GET: /Radiology/Details/5

        public ViewResult Details(int id)
        {
            return View(radiologyRepository.Find(id));
        }

        //
        // GET: /Radiology/Create

        public ActionResult Create()
        {
			ViewBag.PossibleGroups = radiologygroupRepository.All;
			ViewBag.PossibleAttachments = radiologyattachmentRepository.All;
            return View();
        } 

        //
        // POST: /Radiology/Create

        [HttpPost]
        public ActionResult Create(Radiology radiology)
        {
            if (ModelState.IsValid) {
                radiologyRepository.InsertOrUpdate(radiology);
                radiologyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleGroups = radiologygroupRepository.All;
				ViewBag.PossibleAttachments = radiologyattachmentRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Radiology/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleGroups = radiologygroupRepository.All;
			ViewBag.PossibleAttachments = radiologyattachmentRepository.All;
             return View(radiologyRepository.Find(id));
        }

        //
        // POST: /Radiology/Edit/5

        [HttpPost]
        public ActionResult Edit(Radiology radiology)
        {
            if (ModelState.IsValid) {
                radiologyRepository.InsertOrUpdate(radiology);
                radiologyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleGroups = radiologygroupRepository.All;
				ViewBag.PossibleAttachments = radiologyattachmentRepository.All;
				return View();
			}
        }

        //
        // GET: /Radiology/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(radiologyRepository.Find(id));
        }

        //
        // POST: /Radiology/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var r = radiologyRepository.Find(id);
            radiologyRepository.Delete(r);
            radiologyRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

